<template>
  <el-form label-position="left"
           :model="data"
           ref="form"
           style="margin: 10px; width: auto"
  >
    <el-form-item prop="qtType" label="题目">
      <el-input v-model="data.naireName"></el-input>
    </el-form-item>

    <el-form-item>
      <div class="w_full flex-row-reverse-center" style="margin-top: 32px;">
        <el-button size="large" @click="click_ok">确定</el-button>
      </div>
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import {useUserStore} from "@/store/user";
import {reactive, ref} from "vue";
import {ElMessageBox, FormInstance} from "element-plus";
import {api_createExam} from "@/request/apis/examApi";
import {ExamType_Naire} from "@/constants/Constants_ExamType";
import  msg from  '@/components/msg'
const userStore = useUserStore()

const props = defineProps({});
const emit = defineEmits(["close"])
const form = ref<FormInstance>();

const data = reactive({
      naireName: '',
    }
);

const click_ok = async () => {
  if (!data.naireName) {
    await msg.info('请输入名称');
    return;
  }
  const examType = ExamType_Naire;
  const title = data.naireName;
  const creatorCode = userStore.userInfo.userId;
  const r = await api_createExam(examType, creatorCode, title);
  if (!r) {
    await msg.info('创建问卷数据异常', '提示', {
      confirmButtonText: '确定',

    });
    return;
  }
  if (r.code != 0) {
    await msg.info(`创建问卷数据异常!  ${r.code} msg：${r.msg}`, '提示', {
      confirmButtonText: '确定'
    });
    return;
  }
  const examId = r.data.examId;
  //这里调用创建接口
  emit("close", true, examId);
}
</script>

<style scoped>

</style>